package com.woniuxy.stage3demo.mapper.otherPzc;

import com.woniuxy.stage3demo.bean.otherPzc.AdsBean;
import com.woniuxy.stage3demo.bean.otherPzc.PhoneCheckBean;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PhoneCheckMapper {
    /**
     * 新增电核项
     * @param phoneCheck 新增的电核项对象
     * @return 数据库操作的行数
     */
    @Options(useGeneratedKeys = true,keyProperty = "p.id")
    @Insert("Insert into phone_check"+
            "(name,type,check_obj,status,del_flag)"+
            "values(#{p.name},#{p.type},#{p.checkObj},1,0)")
    int savePhoneCheck(@Param("p") PhoneCheckBean phoneCheck);
    /**
     * 删除电核项
     * @param id 删除的电核项对象的id
     * @return 数据库操作的行数
     */
    @Update("update phone_check set del_flag=1 where id=#{id}")
    int deletePhoneCheck(@Param("id")int id);

    /**
     * 修改电核项
     * @param phoneCheck 修改的电核项对象
     * @return 操作行数
     */
    @Update("<script>" +
            "update phone_check" +
            "<set>" +
            "<if test='p.name != null'>" +
            " name = #{p.name}," +
            "</if>" +
            "<if test='p.type != null'>" +
            " type = #{p.type}," +
            "</if>" +
            "<if test='p.checkObj != null'>" +
            " check_obj = #{p.checkObj}," +
            "</if>" +
            "<if test='p.status != null'>" +
            " status = #{p.status}," +
            "</if>" +
            "</set>" +
            "where id = #{p.id}" +
            "</script>")
    int updatePhoneCheck(@Param("p")PhoneCheckBean phoneCheck);

    /**
     * 分页查询
     *
     * @param request
     * @param phoneCheck
     * @return
     */
    List<PhoneCheckBean> findAllByParams(@Param("p") PageRequest request, @Param("ph")PhoneCheckBean phoneCheck);

    @ResultType(String.class)
    @Select("SELECT check_obj FROM phone_check GROUP BY check_obj ORDER BY id ASC;")
    List<String> findAllCategory();
}
